package hu.mapro.gwtui.gxt.client.ui;

import hu.mapro.gwtui.client.data.EntityRequestMethods;
import hu.mapro.gwtui.gxt.client.modelkeyprovider.entity.LongIdModelKeyAdapter;
import hu.mapro.model.Getter;
import hu.mapro.model.LongId;
import hu.mapro.model.Setter;
import hu.mapro.model.meta.Field;
import hu.mapro.model.meta.HasLabel;

import com.google.common.base.Supplier;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.sencha.gxt.data.shared.ModelKeyProvider;

public class EntityRecordsEditor<
	T extends EntityProxy&LongId, 
	F extends Field<T,?>&Getter<T, ? extends Comparable<?>>,
	//RO extends Field<T,?>&HasLabel&Getter<T, ?>,
	RW extends Field<T,?>&HasLabel&Getter<T, ?>&Setter<T, ?>
> extends ComplexRecordsEditor<T, F> {

	
	private Supplier<? extends EntityRequestMethods<T>> requestContextFactory;

//	@Override
//	protected hu.mapro.gwtui.gxt.client.recordseditor.requestfactory.Interface<T> createRequestFactoryAdapter() {
//		return new hu.mapro.gwtui.gxt.client.recordseditor.requestfactory.entity.Adapter<T>(new Adapter<EntityRequestMethods<T>>(requestContextFactory));
//	}

	@Override
	protected ModelKeyProvider<? super T> createModelKeyAdapter() {
		return new LongIdModelKeyAdapter();
	}

	public void setRequestContextFactory(
			Supplier<? extends EntityRequestMethods<T>> requestContextFactory) {
		this.requestContextFactory = requestContextFactory;
	}

	@Override
	public void build() {
		
		super.build();
	}

	protected hu.mapro.gwtui.gxt.client.recordseditor.requestfactory.entity.Adapter<T> createPersistenceAdapter() {
		return new hu.mapro.gwtui.gxt.client.recordseditor.requestfactory.entity.Adapter<T>(new hu.mapro.gwtui.gxt.client.recordseditor.requestfactory.supplier.RequestContextHolderAdapter<EntityRequestMethods<T>>(requestContextFactory));
	}
	
	
}
